
// #include "jncValidate.h"

#include "abstractTree.h"
// #include "examples/ncurses.h"
// #include "examples/gtk.h"
// #include "examples/qt.h"
#include "config.h"

using namespace awa;


void readElement( XercesDOMNode& element ) {
  
  std::cerr << "**********" << std::endl;
  if( element.nodename.length() )
    std::cerr << "NODENAME: " << element.nodename << std::endl ;
  if( element.nodevalue.length() )
    std::cerr << "NODEVALUE: " << element.nodevalue << std::endl ;
  if( element.namespaceuri.length() )
    std::cerr << "NAMESPACEURI: " << element.namespaceuri << std::endl ;
  if( element.prefx.length() )
    std::cerr << "PREFIX: " << element.prefx << std::endl ;
  if( element.localname.length() )
    std::cerr << "LOCALNAME: " << element.localname << std::endl;
  
  switch( element.type ) {
  case XercesDOMNode::value_type::ELEMENT_NODE :
    std::cerr << "ELEMENT" << std::endl;
    break;
  case XercesDOMNode::value_type::ATTRIBUTE_NODE :
    std::cerr << "ATTRIBUTE" << std::endl;
    break;
  case XercesDOMNode::value_type::TEXT_NODE :
    std::cerr << "TEXT" << std::endl;
    break;
  case XercesDOMNode::value_type::CDATA_SECTION_NODE :
    std::cerr << "CDATA_SECTION" << std::endl;
    break;
  case XercesDOMNode::value_type::ENTITY_REFERENCE_NODE  :
    std::cerr << "ENTITY_REFERENCE" << std::endl;
    break;
  case XercesDOMNode::value_type::ENTITY_NODE :
    std::cerr << "ENTITY" << std::endl;
    break;
  case XercesDOMNode::value_type::PROCESSING_INSTRUCTION_NODE :
    std::cerr << "PROCESSING_INSTRUCTION" << std::endl;
    break;
  case XercesDOMNode::value_type::COMMENT_NODE :
    std::cerr << "COMMENT" << std::endl;
    break;
  case XercesDOMNode::value_type::DOCUMENT_NODE :
    std::cerr << "DOCUMENT" << std::endl;
    break;
  case XercesDOMNode::value_type::DOCUMENT_TYPE_NODE :
    std::cerr << "DOCUMENT_TYPE" << std::endl;
    break;
  case XercesDOMNode::value_type::DOCUMENT_FRAGMENT_NODE :
    std::cerr << "DOCUMENT_FRAGMENT" << std::endl;
    break;
  case XercesDOMNode::value_type::NOTATION_NODE :
    std::cerr << "NOTATION" << std::endl;
    break;
  default :
    std::cerr << "UNKNOWN" << std::endl;
    break;
  }
  std::cerr << "**********" << std::endl;
}


int main(int argc, char** argv) 
{
// #ifdef HAVE_GTKMM_H  
//   getGtkNamespace();
// #endif
// #ifdef HAVE_NCURSES_H
//   getNcursesNamespace();
// #endif
// #ifdef HAVE_QT_H
//   getQtNamespace();
// #endif
  //  getPrimitivesNamespace();
  
  assert( argc > 1 && argv[1] != NULL );
  
  awa::ComputationFlow flow( readFromSrc( argv[1] ) );
  
  std::for_each(flow->level_order_begin(), flow->level_order_end(),
  		std::ptr_fun( &readElement ) );
  

  // XmlErrorHandler e_hdl;
//   try {
//     XmlTree xml_rd(&e_hdl, SHOW_ALL, FEATNONE);
//     char file[127];
//     std::string prompt;
// #ifdef HAVE_NCURSES_H
//     prompt += "[ncurses.xml] ";
// #endif
// #ifdef HAVE_GTKMM_H
//     prompt += "[gtk.xml]";
// #endif
// #ifdef HAVE_QT_H
//     prompt += "[qt.xml]";
// #endif
    
//     std::cout << "Please select an xml file to run ( " << prompt << " )";
//     std::cin >> file ;
//     xml_rd.parse("examples/xml", file);
//     if(e_hdl.status() != XmlErrorHandler::PASSED)
//       std::cout << e_hdl.translate() << std::endl;
//     if(e_hdl.status() == XmlErrorHandler::FAIL)
//       exit(1);
//     std::list<JncContext> elm;
//     for(XmlTree::XmlIterator i = xml_rd.begin(); i != xml_rd.end(); i++)
//       {
// 	int cnt(elm.size());
// 	Parse(elm, (XmlTree::XmlTreeWalker*)&i);
// 	if(elm.size() != cnt)
// 	  std::for_each(elm.begin(), elm.end(), std::ptr_fun<JncContext&, void>(eval));
// 	else
// 	  {
// 	    TagNode t(((XmlTree::XmlTreeWalker*)&i)->getNode());
// 	    std::cout << "Warning fn " << t.nodeName() 
// 		      << " not found...skipped" << std::endl;
// 	  }
//       }
//   }catch(std::exception& e)
//     {
//       std::cout << "Exception :\n" << e.what() << std::endl;
//       exit(1);
//     }
//   sleep(4);
}


